Skip to content

F 1483 : Fix SHA-1 prefix match overwriting SHA-256/384/512 output#216

Merged
JacobBarthelmeh merged 3 commits intowolfSSL:mainfrom
miyazakh:f-1483_sha1prefix
Apr 17, 2026
Merged

F 1483 : Fix SHA-1 prefix match overwriting SHA-256/384/512 output#216
JacobBarthelmeh merged 3 commits intowolfSSL:mainfrom
miyazakh:f-1483_sha1prefix

Conversation

@miyazakh
Copy link
Copy Markdown
Contributor

@miyazakh miyazakh commented Apr 2, 2026

Summary

  • XSTRNCMP(alg, "sha", 3) in wolfCLU_hash and wolfCLU_hashSetup
    matched "sha256", "sha384", and "sha512", causing SHA-1 to overwrite
    the correct digest and size
  • Fixed by adding XSTRLEN(alg) == 3 guard to the SHA-1 branch in
    clu_hash.c and clu_hash_setup.c
  • Fixed algCheck loop in clu_hash_setup.c to use XSTRCMP for
    exact matching instead of prefix matching

Depend on : #211 (Fixed)
Depend on : #219

Copilot AI review requested due to automatic review settings April 2, 2026 04:01
@miyazakh miyazakh self-assigned this Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an algorithm-selection bug in the CLI hash command where SHA-1 prefix matching could incorrectly override SHA-256/384/512 digest output, and tightens algorithm validation to require exact matches.

Changes:

  • Guard SHA-1 selection in wolfCLU_hash / wolfCLU_hashSetup with XSTRLEN(alg) == 3 so only "sha" maps to SHA-1.
  • Change hash algorithm validation to exact string matching (XSTRCMP) to avoid prefix-based acceptance.
  • Broaden OCSP interop test error-message matching; update clu_x509_sign.c hash-type switch version gating / case handling.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/hash/clu_hash.c Prevents SHA-1 branch from matching sha256/sha384/sha512 by requiring exact "sha".
src/hash/clu_hash_setup.c Requires exact algorithm match during argument validation and ensures SHA-1 size only applies to "sha".
tests/ocsp/ocsp-interop-test.sh Accepts additional common “file not found” phrasing in Test 6 logs.
src/x509/clu_x509_sign.c Adjusts conditional compilation for unsupported hash-type cases in certificate signing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/x509/clu_x509_sign.c Outdated
@miyazakh miyazakh force-pushed the f-1483_sha1prefix branch from e43bb6a to 1a11f72 Compare April 7, 2026 21:13
@miyazakh miyazakh marked this pull request as ready for review April 7, 2026 21:13
Copilot AI review requested due to automatic review settings April 7, 2026 21:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hash/clu_hash_setup.c Outdated
Comment thread src/hash/clu_hash.c Outdated
Comment thread src/hash/clu_hash_setup.c
Copy link
Copy Markdown
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐺 Skoll Code Review

Overall recommendation: APPROVE
Findings: 2 total — 2 posted, 0 skipped

Posted findings

  • [Medium] Remaining XSTRNCMP calls could be made consistent with the fixsrc/hash/clu_hash.c:104
  • [Low] The fix is correct but the if-chain ordering is fragilesrc/hash/clu_hash.c:108-127

Review generated by Skoll via openclaw

Comment thread src/hash/clu_hash.c
Comment thread src/hash/clu_hash.c
@dgarske dgarske assigned miyazakh and unassigned wolfSSL-Bot Apr 10, 2026
Copilot AI review requested due to automatic review settings April 17, 2026 02:52
@miyazakh miyazakh force-pushed the f-1483_sha1prefix branch from e1ea92c to 77d7867 Compare April 17, 2026 02:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/hash/clu_hash.c:135

  • The Blake2b error handling returns immediately on non-zero ret, which bypasses the common cleanup path (zeroing + freeing input/output). This leaks memory and can leave sensitive data in heap pages on error. Prefer setting ret and falling through to the existing cleanup/return logic (or add a shared cleanup: label) instead of early returns here.
    if (ret == WOLFCLU_SUCCESS && XSTRCMP(alg, "blake2b") == 0) {
        ret = wc_InitBlake2b(&hash, size);
        if (ret != 0) return ret;
        ret = wc_Blake2bUpdate(&hash, input, inputSz);
        if (ret != 0) return ret;
        ret = wc_Blake2bFinal(&hash, output, size);
        if (ret != 0) return ret;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@miyazakh miyazakh assigned wolfSSL-Bot and unassigned miyazakh Apr 17, 2026
@JacobBarthelmeh JacobBarthelmeh merged commit 2c692df into wolfSSL:main Apr 17, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants